//
//  EFBAviationMapDB.m
//  Pods
//
//  Created by E.F.B on 15-5-26.
//
//

#import "EFBAviationMapDB.h"
#import "EFBChartDataBaseUtil.h"
#import "ChartContext.h"

@implementation EFBAviationMapDB

+ (NSArray *)getAllAviationMapInfo
{
    __block NSMutableArray *array = [NSMutableArray array];
    FMDatabaseQueue *dbQueue = [EFBChartDataBaseUtil getChartDatabase];
    [dbQueue inDatabase:^(FMDatabase *db)
     {
         if (![db open]) {
             NSLog(@"Could not open DB.");
             return ;
         }
         
         // kind of experimentalish.
         [db setShouldCacheStatements:YES];
         
         if ( ![db tableExists:@"aviationMap_info"] )
         {
             return ;
         }
         FMResultSet *dataRs = nil;
         dataRs = [db executeQuery:@"select * from aviationMap_info"];
         
         while ([dataRs next])
         {
             [array addObject:[dataRs resultDictionary] ];
         }
         
         [dataRs close];
         [db close];
     }];
    return array;
}

+ (NSMutableArray *)getTheAviationChartsByCode4:(NSString *)code4
{
    __block NSMutableArray *array = [NSMutableArray array];
    FMDatabaseQueue *dbQueue = [EFBChartDataBaseUtil getChartDatabase];
    [dbQueue inDatabase:^(FMDatabase *db)
     {
         if (![db open]) {
             NSLog(@"Could not open DB.");
             return ;
         }
         
         // kind of experimentalish.
         [db setShouldCacheStatements:YES];
         
         if ( ![db tableExists:@"aviationMap_info"] )
         {
             return ;
         }
         FMResultSet *dataRs = nil;
         if (code4){
             dataRs = [db executeQuery:@"select * from aviationMap_info where airportCode4 = ?",code4];
         }
         
         while ([dataRs next])
         {
             [array addObject:[dataRs resultDictionary] ];
         }
         
         [dataRs close];
         [db close];
     }];
    return array;
}

@end
